//电子请假条

class Leave {
    School school 
    Teacher teacher   // 请假的老师
    Date startTime  = new Date()
    Date endTime  = new Date() //
    Teacher approver // 审批人
    String reason = '' // 请假原因
    Boolean pass // 是否同意
    String deny = ''//不同意原因

    static constraints = { 
        school( blank: false); 
        teacher( blank: false);  
        startTime()
        endTime(validator: {val, obj ->
            obj.properties['startTime'] < val
        })
        approver()
        reason(size:0..1000,blank:false)
        pass(nullable: true)
        deny()
    }

    static mapping = {
       table 'xedu_leave'
    }

    String toTitle() { 
        if (pass == null) {
            return "未批示。"
        }else{
            return "${approver}${pass? '已': '不'}同意此次请假。"
        } 
    }
    String toString() { 
        "${teacher}"
    }

}
